
// Copyright (c) 2009 Mohannad Alharthi (mohannad.harthi@gmail.com)
// All rights reserved.
// This source code is licensed under the BSD license, which can be found in
// the LICENSE.txt file.

#include <iostream>
#include <vector>

#include "lexer.h"
#include "parser.h"
#include "misc.h"

#ifdef _TEST_BUILD
extern void RunTests();
#endif

void print(Token tok) {
  std::cout << tok.lexeme() /*<< " | " << tok.code()*/ << std::endl;
}

void main(int argc, char* argv[]) {
#ifdef _TEST_BUILD
  RunTests();
#else
  //std::cout << GetTokenString(kPlus) << std::endl;
  std::cout << "Simple C Compiler" << std::endl;
  // Get all the tokens in the specified source file
  if (argc < 2)
    return;

  std::vector<Message> errors_list;
  Lexer lexer(argv[1], &errors_list);
  

  Parser parser(&lexer, &errors_list);
  TranslationUnit* unit = parser.parse();

  //SymbolTable symbol_table(NULL);
  //Token token = lexer.getNextToken(symbol_table);

  //do {
  //  std::cout << token.lexeme() /*<< " | " << token.code()*/ << std::endl;
  //  token = lexer.getNextToken(symbol_table);
  //} while (token.code() != END_OF_FILE);

  if (!errors_list.empty()) {
    std::cout << "\nErrors: " << std::endl;
    std::vector<Message>::iterator it;
    for (it = errors_list.begin(); it != errors_list.end(); it++)
      std::cout << it->message() << std::endl;
  }
#endif // _TEST_BUILD
}
